package cn.iocoder.yudao.module.myerp.service.SKCproduct;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.myerp.controller.admin.SKCproduct.vo.*;
import cn.iocoder.yudao.module.myerp.dal.dataobject.SKCproduct.ErpProductSkcDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.myerp.dal.mysql.SKCproduct.ErpProductSkcMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.myerp.enums.ErrorCodeConstants.*;

/**
 * ERP SKC级产品 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ErpProductSkcServiceImpl implements ErpProductSkcService {

    @Resource
    private ErpProductSkcMapper erpProductSkcMapper;

    @Override
    public Long createErpProductSkc(ErpProductSkcSaveReqVO createReqVO) {
        // 插入
        ErpProductSkcDO erpProductSkc = BeanUtils.toBean(createReqVO, ErpProductSkcDO.class);
        erpProductSkcMapper.insert(erpProductSkc);
        // 返回
        return erpProductSkc.getId();
    }

    @Override
    public void updateErpProductSkc(ErpProductSkcSaveReqVO updateReqVO) {
        // 校验存在
        validateErpProductSkcExists(updateReqVO.getId());
        // 更新
        ErpProductSkcDO updateObj = BeanUtils.toBean(updateReqVO, ErpProductSkcDO.class);
        erpProductSkcMapper.updateById(updateObj);
    }

    @Override
    public void deleteErpProductSkc(Long id) {
        // 校验存在
        validateErpProductSkcExists(id);
        // 删除
        erpProductSkcMapper.deleteById(id);
    }

    private void validateErpProductSkcExists(Long id) {
        if (erpProductSkcMapper.selectById(id) == null) {
            throw exception(ERP_PRODUCT_SKC_NOT_EXISTS);
        }
    }

    @Override
    public ErpProductSkcDO getErpProductSkc(Long id) {
        return erpProductSkcMapper.selectById(id);
    }

    @Override
    public PageResult<ErpProductSkcDO> getErpProductSkcPage(ErpProductSkcPageReqVO pageReqVO) {
        return erpProductSkcMapper.selectPage(pageReqVO);
    }

}